//
//  MinePublishViewController.m
//  Find
//
//  Created by lanou3g on 15/10/29.
//  Copyright © 2015年 Reiko. All rights reserved.
//

#import "MinePublishViewController.h"

@interface MinePublishViewController ()<UITableViewDataSource, UITableViewDelegate>



@end

@implementation MinePublishViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
     self.view.backgroundColor = [UIColor colorWithRed:87/255.0 green:191/255.0 blue:255/255.0 alpha:1];
    // 调用 添加界面内容
    [self addSubViews];
}

#pragma mark  -- 添加页面内容
- (void)addSubViews
{
    // 判断是收藏还是发布 页面主题改变 以及数据处理
    if (self.minePublishCollec) {
        // 收藏主题
        self.navigationItem.title = @"我的收藏";
        
        // 数据数组 测试用
        NSArray * array = @[@"诸葛亮", @"刘备", @"张飞", @"关羽", @"赵子龙", @"曹操", @"孙策", @"周瑜"];
        self.minePublishArray = [NSMutableArray arrayWithArray:array];

        
    } else {
    // 发布主题
    self.navigationItem.title = @"我的发布";
        
        // 数据数组 测试用
        NSArray * array = @[@"孙悟空", @"抓八戒", @"沙悟净", @"白龙马", @"唐三藏", @"白骨精", @"黑熊精"];
        // 将数组转化为可变数组
        self.minePublishArray = [NSMutableArray arrayWithArray:array];

    }
    
    // 设置navigationBar 背景颜色 用图片
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"iconfont-navbar-back"] forBarMetrics:UIBarMetricsDefault];
    
    
#pragma  mark -- tableview
    self.minePublishTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 113) style:(UITableViewStylePlain)];
    // 设置导航条不透明
//    self.navigationController.navigationBar.translucent = NO;
    self.minePublishTableView.delegate = self;
    self.minePublishTableView.dataSource = self;
    [self.view addSubview:self.minePublishTableView];
    
    
#pragma  mark -- 右上角管理编辑状态
    UIBarButtonItem * minePublishRightBar = [[UIBarButtonItem alloc] initWithTitle:@"编辑" style:(UIBarButtonItemStyleDone) target:self action:@selector(minePublishRIghtAction:)];
    self.navigationItem.rightBarButtonItem = minePublishRightBar;
    
}

#pragma mark -- 实现右上角按钮编辑
- (void)minePublishRIghtAction:(UIBarButtonItem *)rightBar
{
    NSLog(@"编辑状态");
    // 开启编辑状态
    [self.minePublishTableView setEditing:!self.minePublishTableView.editing animated:YES];
    // 更改编辑按钮
    if (self.minePublishTableView.editing == YES) {
        rightBar.title = @"完成";
    } else {
        rightBar.title = @"编辑";
    }
}

#pragma mark -- 实现tableview代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.minePublishArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * identifier = @"lostViewController";
    LostListTableViewCell * Listcell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (Listcell == nil) {
        Listcell = [[LostListTableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:identifier];
    }
    Listcell.backgroundColor = [UIColor whiteColor];
    
    Listcell.listTitleLabel.text = self.minePublishArray[indexPath.row];
    
    return Listcell;
    
}

// 返回每一行高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 130;
}

#pragma mark --  删除数据
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // 删除数组中数据
        [self.minePublishArray removeObjectAtIndex:indexPath.row];
        // 删除界面中数据
        [self.minePublishTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:(UITableViewRowAnimationLeft)];
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
